﻿using System;
using System.ComponentModel;
using System.Net;
using System.Threading.Tasks;
using ePipe;
using Letter.Net.Session;

namespace Letter.Net;

public abstract class AConnection
{
    [EditorBrowsable(EditorBrowsableState.Never)]
    public void Init(ISession session)
    {
        this.session = session;
    }

    private ISession session;

    public string Id => this.session.Id;
    public bool Active => this.session.Active;
    public EndPoint LocalEndPoint => this.session.LocalEndPoint;
    public EndPoint RemoteEndPoint => this.session.RemoteEndPoint;
    protected virtual IDuplexPipe<byte> Transport => this.session.Transport;
    public ValueTask CloseAsync() => this.session.CloseAsync();

    public abstract void OnActive();
    public abstract void OnInactive();
    public abstract void OnException(Exception ex);
}